package com.xnjx.controller;

import com.xnjx.utils.RtspToMP4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/RtspApi")
//@Api(tags = "流操作")
public class RtspToMP4Controller {
    @Autowired
    private RtspToMP4 rtspToMP4;

    private Map<Integer,Process> map=new HashMap<>();

//    @ApiOperation(value = "开始录制")
    @GetMapping(value = "/videoRecordStart")
    public void Start(Integer id, String FileName) {
        /*String ffmpegPath="D:\\work\\Test\\ffmpeg.exe";*/
        String ffmpegPath="ffmpeg";
        String streamUrl="rtsp://admin:xnjx888888@192.168.2.21:554/h264/ch1/main/av_stream";
        /*String FilePath="D:\\work\\Test\\2022-01-06\\"+FileName;*/
        String FilePath="/opt/videomp4/"+FileName;
        Process process = rtspToMP4.StartRecord(ffmpegPath, streamUrl, FilePath);
        if(null!=process){
            map.put(id,process);
//            return new SuccessResponseData();
        }
//        return new ErrorResponseData(1,"开始录制错误");
    }

//    @ApiOperation(value = "结束录制")
    @GetMapping(value = "/videoRecordStop")
    public void stop(Integer id) {
        if(map.containsKey(id)){
            Process process = map.get(id);
            if(null!=process){
                rtspToMP4.stopRecord(process);
//                return new SuccessResponseData();
            }
        }
//        return new ErrorResponseData(1,"结束录制错误");
    }

    @GetMapping(value = "/aa")
    public String aa(){
        return "aa";
    }
}
